<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        .error{
            font-size: 12px;
            color: red;
            height: 20px;
        }
    </style>
    <script src="/html/axios.min.js"></script>
    <script src="/html/util.js"></script>
    <script>
        function register(){
            axios.get("/user/register",{
                params:{
                    userName:$("userName").value,
                    pwd:$("pwd").value,
                    money:$("money").value,
                    email:$("email").value
                }
            }).then(e =>{
                var info = e.data;
                if(info == "ok"){//注册成功，页面跳转
                    location.href = "/html/index.html";
                }
                else{//注册失败，显示错误信息
                    for(var i=0;i<info.length;i++){
                        $(info[i].field+"Div").innerHTML = info[i].defaultMessage;
                    }
                }
            });
        }

        function update(){
            axios.get("/user/update",{
                params:{
                    pwd:$("pwdUpdate").value
                }
            }).then(e => {
                var info = e.data;
                var str = "";
                for(var i=0;i<info.length;i++){
                    str += `${info[i].defaultMessage}<br>`;
                }
                $("updateErrorDiv").innerHTML = str;
            });
        }
    </script>
</head>
<body>
    用户名：<input type="text" id="userName">
    <div class="error" id="userNameDiv"></div>
    密码：<input type="password" id="pwd">
    <div class="error" id="pwdDiv"></div>
    工资：<input type="number" id="money"><br>
    <div class="error" id="moneyDiv"></div>
    电子邮件：<input type="text" id="email"><br>
    <div class="error" id="emailDiv"></div>
    <input type="button" value="注册" onclick="register()">
    <hr>
    密码：<input type="text" id="pwdUpdate"><br>
        <div id="updateErrorDiv"></div>
        <input type="button" value="修改" onclick="update()">
</body>
</html>